<?php

Class Hashing
{
	public static function intHash($no,$max = 5000)
	{
		if (!is_numeric($no)) die('Value must be numeric');
		$p0 = ceil($no / ($max * $max));
		$p1 = ceil($no % $max);
		return $p0.'/'.sprintf('%0'.strlen($max).'d', $p1);
	}
	
	public static function crc32Hash($key,$max = 5000)
	{
		return (crc32($key) & 0x7fffffff) % $max;
	}
	
	public static function adler32Hash($str,$lv = 2)
	{
		$pathinfo = pathinfo($str);
		$extension = $pathinfo['extension'];
		$filename = $pathinfo['filename'];
		$hash = hash('adler32',$filename);
		$dir = array();
		for($i=1;$i <= $lv;$i++){
			array_push($dir,substr($hash,0,$i));
		}
		$path = implode('/',$dir).'/'.$hash;
		if(!empty($extension)){
			$path .= '.'.$extension;
		}
		return $path;
	}
}